package com.xyf.sys.config;


import com.fdd.api.conf.FddApiConfig;
import com.lop.open.api.sdk.DefaultDomainApiClient;
import com.yl.jms.sdk.JtExpressApi;
import com.yl.jms.sdk.auth.ClientConfiguration;
import com.yl.jms.sdk.client.JtExpressApiOperator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author R-H
 * @Date 2024/2/271735
 * @Description
 */
@Configuration
public class CustomConfig {

    @Value("${yundaex.appKey}")
    private String yundaexAppKey;

    @Value("${yundaex.appSecret}")
    private String yundaexAppSecret;

    @Value("${sto.appKey}")
    private String stoAppKey;

    @Value("${sto.code}")
    private String stoCode;

    @Value("${sto.secretKey}")
    private String stoSecretKey;

    @Value("${kuaimai.appid}")
    private String kuaimaiAppid;

    @Value("${kuaimai.secret}")
    private String kuaimaiSecret;
    @Value("${jt.apiAccount}")
    private String apiAccount;
    @Value("${jt.privateKey}")
    private String privateKey;
    @Value("${jt.customerCode}")
    private String customerCode;
    @Value("${jt.orderPassword}")
    private String orderPassword;
    @Value("${jd.appKey}")
    private String appKey;
    @Value("${jd.appSecret}")
    private String appSecret;
    @Value("${jd.serverUrl}")
    private String serverUrl;
    @Value("${fdd.appid}")
    private String fddAppid;
    @Value("${fdd.appSecret}")
    private String fddAppSecret;
    @Value("${aliyun.accessKey}")
    private String accessKey;
    @Value("${aliyun.accessKeySecret}")
    private String accessKeySecret;

    @Bean
    public YundaexConfig yundaexConfig(){
        return new YundaexConfig(yundaexAppKey, yundaexAppSecret);
    }

    @Bean
    public STOConfig stoConfig(){
        return new STOConfig(stoAppKey, stoCode, stoSecretKey);
    }

//    @Bean
//    public KuaimaiClient kuaimaiClient(){
//        return KuaimaiClient.createClient(kuaimaiAppid,kuaimaiSecret);
//    }

    @Bean
    public JtExpressApi jtExpressApi(){
        //创建授权用户实体
        ClientConfiguration clientConfiguration = new ClientConfiguration(apiAccount,privateKey);
        //当调用postByCustom方法时需要customerCode和orderPassword
        clientConfiguration.setCustomerCode(customerCode);
        clientConfiguration.setCustomerPwd(orderPassword);
        return new JtExpressApiOperator(clientConfiguration);
    }

    @Bean
    public DefaultDomainApiClient defaultDomainApiClient(){
        //生产域名：https://api.jdl.com 预发环境域名：https://uat-api.jdl.com
        //使用JOS应用调用物流开放平台接口
        return new DefaultDomainApiClient(serverUrl,500,15000);
    }

    @Bean
    public FddApiConfig fddApiConfig(){
        FddApiConfig fddApiConfig = new FddApiConfig();
        fddApiConfig.setAppId(fddAppid);
        fddApiConfig.setAppId(fddAppSecret);
        return fddApiConfig;
    }

    @Bean
    public com.aliyun.dysmsapi20170525.Client client(){
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 必填，请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
                .setAccessKeyId(accessKey)
                // 必填，请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
                .setAccessKeySecret(accessKeySecret);
        // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
        config.endpoint = "dysmsapi.aliyuncs.com";
        try {
            return new com.aliyun.dysmsapi20170525.Client(config);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public class YundaexConfig {
        private String appkey;
        private String appSecret;

        public YundaexConfig(String appkey, String appSecret) {
            this.appkey = appkey;
            this.appSecret = appSecret;
        }

        public String getAppkey() {
            return appkey == null ? null : appkey.trim();
        }

        public String getAppSecret() {
            return appSecret == null ? null : appSecret.trim();
        }
    }

    public class STOConfig {

        private String appKey;

        private String code;

        private String secretKey;

        public STOConfig(String appKey, String code, String secretKey) {
            this.appKey = appKey;
            this.code = code;
            this.secretKey = secretKey;
        }

        public String getAppKey() {
            return appKey == null ? null : appKey.trim();
        }

        public String getCode() {
            return code == null ? null : code.trim();
        }

        public String getSecretKey() {
            return secretKey == null ? null : secretKey.trim();
        }
    }
}
